<template>
	<view class="page tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<view class="top-bg"></view>
		<dawnBar title="住院预交-住院记录"></dawnBar>
		<view class="page-container" style="padding-bottom: 140rpx;">
			<pBox @search="getPage()" :search="true"></pBox>
			<view class="order--wrap tn-margin-top-sm">
				<!-- 标签内容 -->
				<view class="list">
					<view class="list-item" v-for="(item,index) in list" :key="index">
						<view class="list-head tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between">
							<view>
								<text class="tn-color-black">住院号：</text>
								<text class="tn-color-dawn tn-text-lg tn-text-bold">{{ item.inPatientNo  || '' }}</text>
							</view>
							<view>
								<view class="justify-content-item ">
									<tn-tag backgroundColor="tn-main-gradient-dawn" fontColor="#FFFFFF"
										shape="circleLeft" width="auto">
										<text v-if="item.status === '0'">在院 无费用</text>
										<text v-else-if="item.status === '1'">入院申请</text>
										<text v-else-if="item.status === '2'">住院中</text>
										<text v-else-if="item.status === '3'">可办理出院</text>
										<text v-else-if="item.status === '4'">已出院</text>
										<text v-else-if="item.status === '5'">在院 无费用</text>
									</tn-tag>
								</view>
							</view>
						</view>
						<view class="list-content tn-flex tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
							<view class="tn-flex tn-flex-nowrap  tn-flex-col-center tn-flex-row-left">
								<view v-if="item.pictures && item.pictures.length > 0">
									<image mode="aspectFill" class="list-content-image" :src="item.pictures[0]">
								</view>
								<view class="">
									<view>
										<text class="tn-color-black">姓名：</text>
										<text class="tn-color-black tn-text-lg tn-text-bold">{{patientInfo.name || '' }}</text>
									</view>
									<view class="tn-margin-top-xs">
										<text class="tn-color-black">科室：</text>
										<text class="tn-text-bold">{{item.departmentName || '' }}</text>
										<text class="tn-color-gray tn-padding-left-xs tn-padding-right-xs">|</text>
										<text class="tn-color-black">病历主页ID：</text>
										<text class="tn-color-dawn tn-text-bold">{{ item.inPatientId  || '' }}</text>
									</view>
									<view class="tn-margin-top-xs">
										<text class="tn-color-black">入院日期：</text>
										<text class="tn-color-dawn tn-text-bold">{{ item.inDate  || '' }}</text>
									</view>
									<view class="tn-margin-top-xs">
										<text class="tn-color-black">入院诊断：</text>
										<text class="dawn-text-sm tn-color-gray">{{ item.inDiagnose  || '' }}</text>
									</view>
								</view>
							</view>

							<!-- <view @click="navLink(item)"
								class="tn-flex tn-flex-nowrap  tn-flex-col-center tn-flex-row-left">
								<view class="justify-content-item tn-text-right">
									<text class="tn-icon-right-double tn-margin-left-xs tn-text-bold tn-color-dawn"></text>
								</view>
							</view> -->
						</view>

						<view class="dawn-line tn-margin-top-sm"></view>
						<view
							class=" tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
							<view class="justify-content-item tn-text-df">
								<!-- <text class="tn-icon-time-fill tn-color-black"></text>
								<text class="tn-color-black">{{ item.inDate  || '' }}</text> -->
							</view>
							<view
								class="tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-right op-box">
								<!-- <tn-button @click="navLink('total',item)" size="sm" class="tn-shadow-blur dawn-btn-sm dawn-btn-sm__info">
									<text class="">总费用</text>
								</tn-button>
								<tn-button @click="navLink('day',item)" size="sm" class="tn-shadow-blur dawn-btn-sm dawn-btn-sm__success">
									<text class="">日清单</text>
								</tn-button>
								<tn-button @click="navLink('record_pre',item)" size="sm" class="tn-shadow-blur dawn-btn-sm dawn-btn-sm__success">
									<text class="">预交记录</text>
								</tn-button> -->
								<tn-button @click="navLink('pre',item)" size="sm" class="tn-shadow-blur dawn-btn-sm dawn-btn-sm__pay">
									<text class="tn-icon-send-fill">缴费</text>
								</tn-button>
							</view>
						</view>
					</view>
				</view>

				<!-- 悬浮按钮-->
				<view class="tn-flex tn-footerfixed">
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<tn-button @click="getPage()" class="dawn-btn-lg dawn-btn-lg__main">
							<text class="tn-icon-search-list-fill tn-padding-right-xs"></text>
							<text>查 询</text>
						</tn-button>
					</view>
				</view>
			</view>
			<view v-if="show">
				<dawnMsg :msg="msg"></dawnMsg>
			</view>
		</view>
		
		<!-- loading -->
		<dawnLoading :show="loading"></dawnLoading>

		<!-- 分页 -->
		<!-- <dawn-pagination ref="pagination" :current="queryData.pageNo" :total="total" @pagination="getPage" /> -->

		<!-- 悬浮按钮-->
		<NavBtn></NavBtn>
	</view>
</template>

<script>
	import page_mixin from '@/mixins/page_mixin.js'
	import dayjs from '@/plugin/dayjs/dayjs.min.js';
	import * as InhospitalApi from "@/api/hospital/inhospital.js";
	import * as api from '@/api/api.js';
	import * as config from "@/api/config.js";
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	const app = getApp();

	export default {
		name: 'order',
		mixins: [page_mixin],
		computed: mapGetters(['appConfig', 'uid', 'isLogin', 'userInfo','patientInfo']),
		data() {
			return {
				loading: false,
				show: false,
				msg: '',
				queryData: {
					pageSize: 10,
					pageNo: 1,
					patientId: '',
					patientName: ''
				},
				status: -1,
				list: []
			}
		},
		async onLoad(options) {
			await this.$onLaunched;
			console.info("query onLoad")
			if (!this.isLogin) {
				this.loading = true;
				toLogin();
				return;
			} else {
				// this.$nextTick(() => {
				// 	this.getPage();
				// })
			}
		},
		methods: {
			search(result) {
				if (result.code === 0) {
					this.queryData = result.data;
					this.queryData.pageNo = 1;
					this.queryData.pageSize = this.$refs.pagination.pageSize;
					// this.getPage();
				}
			},
			getPage: function(page) {
				if (!this.patientInfo.id) {
					this.show = true;
					this.msg = '请先添加就诊人！';
					return;
				}
				let that = this;
				this.loading = true;
				this.show = false;
				this.$set(this, 'list', []);
				this.queryData.patientName = this.patientInfo.name;
				this.queryData.patientId = this.patientInfo.patientId;
				if(this.patientInfo.patientId === '35426'){
					this.queryData.patientId = '674323';
				}
				InhospitalApi.getInhospitalList(this.queryData).then(res => {
					this.loading = false;
					console.table(res);
					if (res.code === 0) {
						const l = res.data || [];
						this.$set(this, 'list', l);
						if (l.length == 0) {
							this.show = true;
							this.msg = '未查询到在院数据';
						}
					} else {
						this.show = true;
						this.msg = res.msg;
					}
				}).catch(err => {
					this.loading = false;
					this.show = true;
				})
			},
			navLink(type,item) {
				var url = '';
				if(type === 'pre'){
					url = '/hosp/inhospital/pre?inPatientId='+item.inPatientId+'&inPatientNo='+item.inPatientNo;
				}else if(type === 'total'){
					url = '/hosp/inhospital/total_cost?inPatientId='+item.inPatientId+'&inPatientNo='+item.inPatientNo;
				}else if(type === 'day'){
					url = '/hosp/inhospital/record_daily?inPatientId='+item.inPatientId+'&inPatientNo='+item.inPatientNo;
				}else if(type === 'record_pre'){
					url = '/hosp/inhospital/record_pre?inPatientId='+item.inPatientId+'&inPatientNo='+item.inPatientNo;
				}
				uni.navigateTo({
					url: url
				})
			},
			formatDate: function(date) {
				return dayjs(date).format("YYYY-MM-DD");
			},
			formatDateTime: function(date) {
				return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>